<?php
namespace app\index\controller;
use think\Controller;
use think\Session;
class User extends Controller
{
    public function signOut()
    {
        session(null);
        return redirect('/User/Login');
    }
    public function login()
    {
        if (isset($_POST["login"])) {
            if (input("post.type")=="user"){
                $res=db('doctor')->where("phone",$_POST["account"])->where("passwd",md5($_POST["passwd"]))->find();
                if($res!=null){
                    session("login",1);
                    session("uid",$res["id"]);
                    session("cid",$res["clinic"]);
                    session("name",$res["name"]);
                    session("type","user");
                    return redirect('/Index/index');
                }
                else $this->error("用户名或密码错误");
            }
            else if (input("post.type")=="admin") {
                $res=db('admin')->where("user",$_POST["account"])->where("passwd",md5($_POST["passwd"]))->find();
                if($res!=null){
                    session("login",1);
                    session("uid",$res["id"]);
                    session("cid",$res["clinic"]);
                    session("name",$res["user"]);
                    session("type","admin");
                    return redirect('/Index/index');
                }
                else $this->error("用户名或密码错误");
            }else return $this->error("登录身份不合法");
        } else {
            return view('login');
        }
        
        
    }
}













